import os
import os.path
from frame_manager import FrameManager
from neo_manager import NeoManager
from shared_enum import Layer
import json

URI = 'neo4j://localhost'
auth = ('neo4j', 'password')
frame_file_path = './tool/Data/frame.json'
ontology_file_path = './tool/Data/TCMLS_Extend.owl'

corpus_dir = './tool/temp/'

frame_manager = FrameManager(frame_file_path, ontology_file_path)

with NeoManager(URI, auth=auth) as neo_manager:
    neo_manager.change_layer('prototype')
    for temp_file in os.scandir(corpus_dir):
        frames = frame_manager.get_frames_from_file(temp_file)
        for frame in frames:
            frame.check(frame.script['check'], frame.script['generate'])
            _frame = frame.script['primary'](frame)
            _frame = _frame.script['prototype'](_frame)
            _frame.save(neo_manager)
        frame_manager.clear_marker()